﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scratchpad
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = new List<Tuple<string, Dictionary<int, bool>>>();
            Console.WriteLine(x.GetType().ToGenericTypeString());
        }
    }

    // source: http://efreedom.com/Question/1-2448800/Given-Type-Instance-Get-Generic-Type-Name-CSharp
    public static class TypeExtensions
    {
        public static string ToGenericTypeString(this Type t)
        {
            if (!t.IsGenericType) return t.Name;
            
            string genericTypeName = t.GetGenericTypeDefinition().Name;
            genericTypeName = genericTypeName.Substring(0, genericTypeName.IndexOf('`'));

            string genericArgs = string.Join(",", t.GetGenericArguments()
                                       .Select(ToGenericTypeString).ToArray());

            return string.Format("{0}<{1}>", genericTypeName, genericArgs);
        }
    }
}
